<!DOCTYPE HTML>
<html lang="cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <%include("/common/header.html",{title:''}){}%>
    <title>报告模板</title>

    <link rel="stylesheet" href="static/layuiadmin/layui/css/layui.css">
    <script type="text/javascript" src="static/layuiadmin/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="js/vue.js"></script>
    <script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

</head>

<body class="layui-anim">
<div class="x-body">
    <div class="layui-row">
        <div class="layui-fluid">
            <div class="layui-card-body">
                <form class="layui-form" lay-filter="component-form-group" id="formId">
                    <div class="layui-form-item">
                        <label class="layui-form-label">标题</label>
                        <div class="layui-input-block">
                            <input type="hidden" name="id" class="layui-input" lay-verify="id">
                            <input type="text" name="title" lay-verify="required" autocomplete="off" placeholder="请输入标题.."
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">内容</label>
                        <div class="layui-input-block">
                            <textarea name="content" lay-verify="required" placeholder="请输入内容..."
                                      class="layui-textarea"></textarea>
                        </div>
                    </div>

                    <div class="layui-form-item" pane="">
                        <label class="layui-form-label">角色</label>
                        <div class="layui-input-block">

                            <% for(t in syslist){ %>
                            <input id="lids" style="width: 20px;margin-left: 10px" class="layui-form-checkbox" lay-verify="required" type="checkbox" name="jundic" value="${t.id}"><span>${t.name}</span>

                            <% } %>

                        </div>
                    </div>
                    <div class="layui-form-item layui-layout-admin">
                        <label for="L_repass" class="layui-form-label"></label>

                        <button class="layui-btn" lay-submit="submission" lay-filter="submission">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
function b1(){
    var v=$(".layui-form-checkbox").val();
    alert(JSON.stringify(v))

}



    $(function () {
        var title = "发布通知";
        var size = ['550px', '450px'];
        var update_url = 'notice/update.jhtml';
        var delete_url = "notice/delete.jhtml";
        var cols = [
            {checkbox: true, fixed: true},
            {field: 'createDate', width: "130", title: '创建时间'},
            {field: 'title', title: '标题', width: "130"},
            {field: 'content', title: '内容', width: "130"},
            {title: '操作', toolbar: '#barDemo', fixed: 'right', align: 'center', width: "180", fixed: 'right'}
        ];


        //
        function loadData(data) {
            var ret = {
                "id": data.id,
                "capacity": data.capacity,
                "cryogen": data.cryogen,
                "heating": data.heating,
                "xinfnorm": data.xinfnorm,
                "dehumidification": data.dehumidification,
                "iteminofId": data.iteminofId,
                "mmanufacturerId": data.mmanufacturerId
            };
            return ret;
        }

        //监听提交
        layui.use('form', function () {
            var form = layui.form;
            //自定义验证规则
            form.verify({
                required: [/[\S]+/, "必填项不能为空"],
                name: function (value) {
                    if (value.length < 4) {
                        return '至少4个字符';
                    }
                }
            });
            //验证通过后提交数据到后台
            form.on('submit(submission)', function (data) {
                //序列化表单方法
                $.fn.ghostsf_serialize = function () {
                    var a = this.serializeArray();
                    var $radio = $('input[type=radio],input[type=checkbox]', this);
                    var temp = {};
                    $.each($radio, function () {
                        if (!temp.hasOwnProperty(this.name)) {
                            if ($("input[name='" + this.name + "']:checked").length == 0) {
                                temp[this.name] = "";
                                a.push({name: this.name, value: ""});
                            }
                        }
                    });
                    console.log(JSON.stringify(a));
                    return a;
                };

                var formObject = {};
                var formArray =$("#formId").ghostsf_serialize();
                $.each(formArray,function(i,item){
                    formObject[item.name] = item.value;
                });
                var checked =[];
                $("input[name=jundic]:checked").each(function(index,itme){
                    checked.push(itme.value)
                });
                formObject["jundic"]=checked.toString();

                postUpdate(data,checked);
                return false;
            });
        });

        window.postUpdate = function (data,checked) {

           var b = checked.join(',');

            // var junid;
            // for (let i = 0; i < checked.length; i++) {
            //     alert(checked[i])
            // }
            $.ajax({
                url: update_url,
                type: "POST",
                data: {
                    "data": JSON.stringify(data.field),
                    "checked":b
                },
                dataType: "json",
                success: function (data) {
                    if (data.code == 0) {
                        layer.closeAll();

                        layer.msg('发布成功', {time:1000, icon: 1},function(){
                            parent.location.reload();
                        });
                    } else {
                        layer.msg(data.msg, {icon: 5});
                    }
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    layer.open({
                        title: "错误信息",
                        type: 1,
                        content: jqXHR.responseText, //statusText
                        btn: ['关闭']
                    });
                }
            });
        }
    });

</script>
</body>
</html>
